use actix_web::{App, web};

use crate::view::index;
use crate::api;
use actix_web::dev::{MessageBody, ServiceRequest, ServiceResponse};
use actix_service::NewService;

pub(crate) struct AppState {}

pub(crate) trait AppExt<T, B> {
    fn config_routes(self) -> Self;
}

impl<T, B> AppExt<T, B> for App<T, B>
    where
        B: MessageBody,
        T: NewService<
            Config=(),
            Request=ServiceRequest,
            Response=ServiceResponse<B>,
            Error=actix_web::Error,
            InitError=(),
        >,
{
    fn config_routes(self) -> Self {
        self.service(web::resource("/").to(index::index))
            .service(web::resource("/api/user/login").to(api::user::login))
    }
}

